home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / tetra.c.bak < prev    next >
Text File  |  1997-08-17  |  3KB  |  200 lines

  1. /*
  2.  * Demonstrate a rotating translating tetrahedron.
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. #ifdef SGI
  8. #include "gl.h"
  9. #include "device.h"
  10. #include "hershey.h"
  11. #else
  12. #include "vogl.h"
  13. #include "vodevice.h"
  14. #endif
  15.  
  16. #ifndef TC
  17. #include <math.h>
  18. #else
  19. extern double sin(), cos();
  20. #endif
  21.  
  22. #define    TETRAHEDRON    1L
  23. #define    NSIDES    3
  24. #define    NFACES    4
  25. #define    NPNTS    4
  26.  
  27. Coord    points[NPNTS][3] = {
  28.     {-0.5, 0.866, -0.667},
  29.     {-0.5, -0.866, -0.667},
  30.     { 1.0, 0.0, -0.667},
  31.     { 0.0, 0.0, 1.334}
  32. };
  33.  
  34. int    faces[NFACES][NSIDES] = {
  35.     {2, 1, 0},
  36.     {0, 1, 3},
  37.     {1, 2, 3},
  38.     {2, 0, 3}
  39. };
  40.  
  41. int    colface[NFACES] = {
  42.         GREEN,
  43.         YELLOW,
  44.         CYAN,
  45.         MAGENTA
  46. };
  47.  
  48. /* ---------------------------------------------------------------------
  49.  * Prototypes:
  50.  */
  51. int main( int, char **);                               /* tetra.c         */
  52. int maketetra(void);                                   /* tetra.c         */
  53.  
  54. /* ---------------------------------------------------------------------
  55.  * Source:
  56.  */
  57.  
  58. int main(
  59.   int argc,
  60.   char **argv)
  61. {
  62.     char    dev[20];
  63.     int    i, but;
  64.     int    rotval = 0, drotval = 2;
  65.     float    R = 1.6, tx = 0.0, tz = R, zeye = 5.0;
  66.     int    do_backface = 0;
  67.     int    do_fill = 0;
  68.     short    val;
  69.  
  70.     for (i = 1; i < argc; i++) {
  71.         if (!strcmp(argv[i], "-b"))
  72.             do_backface = 1;
  73.         if (!strcmp(argv[i], "-f"))
  74.             do_fill = 1;
  75.     }
  76.  
  77.     prefsize(400L, 400L);
  78.  
  79.     winopen("tetra");          /* set up device */
  80.  
  81.     qdevice(ESCKEY);
  82.     qdevice(QKEY);
  83.     unqdevice(INPUTCHANGE);
  84.  
  85.     doublebuffer();
  86.     gconfig();
  87.  
  88.  
  89.  
  90.  
  91.     polymode(PYM_LINE);
  92.     if (do_fill)
  93.         polymode(PYM_FILL);
  94.  
  95.     if (do_backface)
  96.         backface(1);
  97.  
  98.     /*
  99.      * set up a perspective projection with a field of view of
  100.      * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
  101.      * and the far clipping plane at 1000.0.
  102.      */
  103.     perspective(400, 1.0, 0.001, 15.0);
  104.     lookat(0.0, 0.0, zeye, 0.0, 0.0, 0.0, 0);
  105.  
  106.  
  107.     hfont("futura.l");
  108.  
  109.     htextsize(0.05, 0.05);
  110.  
  111.     ortho2(0.0, 1.0, 0.0, 1.0);
  112.  
  113.  
  114.     hboxtext(0.1, 0.4, 0.8, 0.1, "This is Some text");
  115.  
  116.     getchar();
  117.  
  118.     /*
  119.      * Make a tetrahedron object
  120.      */
  121.  
  122.     maketetra();
  123.  
  124.     do {
  125.         for (rotval = 0; rotval < 3600; rotval += drotval) {
  126.             color(BLACK);
  127.             clear();
  128.  
  129.             /*
  130.              * Rotate the whole scene...(this acumulates - hence
  131.              * drotval)
  132.              */
  133.             rotate(drotval, 'x');
  134.             rotate(drotval, 'z');
  135.  
  136.             color(RED);
  137.             pushmatrix();
  138.                 rotate(900, 'x');
  139.                 circ(0.0, 0.0, R);
  140.             popmatrix();
  141.  
  142.             color(BLUE);
  143.             move(0.0, 0.0, 0.0);
  144.             draw(tx, 0.0, tz);
  145.             
  146.             /*
  147.              * Remember! The order of the transformations is
  148.              * the reverse of what is specified here in between
  149.              * the pushmatrix and the popmatrix. These ones don't
  150.              * accumulate because of the push and pop.
  151.              */
  152.             pushmatrix();
  153.                 translate(tx, 0.0, tz);
  154.                 rotate(rotval, 'x');
  155.                 rotate(rotval, 'y');
  156.                 rotate(rotval, 'z');
  157.                 scale(0.4, 0.4, 0.4);
  158.                 callobj(TETRAHEDRON);
  159.             popmatrix();
  160.  
  161.             tz = R * cos((double)(rotval * 3.1415926535 / 180));
  162.             tx = R * sin((double)(rotval * 3.1415926535 / 180));
  163.  
  164.             swapbuffers();
  165.  
  166.             if (qtest()) {
  167. /*
  168.                 but = (int)qread(&val);
  169.                 fprintf(stderr, "but = %c (%d)\n", but, but);
  170. */
  171.                 gexit();
  172.                 exit(0);
  173.             }
  174.         }
  175.  
  176.     } while (1);
  177. }
  178.  
  179. /*
  180.  * maketetra
  181.  *
  182.  *    draw a tetrahedron
  183.  */
  184. int maketetra(void)
  185. {
  186.     int    i, j;
  187.  
  188.     makeobj(TETRAHEDRON);
  189.  
  190.     for (i = 0; i < NFACES; i++) {
  191.         color(colface[i]);
  192.         bgnpolygon();
  193.             for (j = 0; j < NSIDES; j++) 
  194.                 v3f(points[faces[i][j]]);
  195.         endpolygon();
  196.     }
  197.  
  198.     closeobj();
  199. }
  200.